package pers.xiaojun.boot.module.infra.convert.file;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import pers.xiaojun.boot.file.core.enums.FileStorageEnum;
import pers.xiaojun.boot.module.infra.controller.file.vo.config.FileConfigSaveReqVO;
import pers.xiaojun.boot.module.infra.dao.entity.FileConfigDO;

/**
 * 文件配置转换
 *
 * @author xiaojun
 * @since 2025-11-16
 */
@Mapper
public class FileConfigConvert {

    public static FileConfigConvert INSTANCE = Mappers.getMapper(FileConfigConvert.class);

    /**
     * 转换为文件配置 DO
     *
     * @param reqVO 文件配置请求VO
     * @return 文件配置 DO
     */
    public FileConfigDO toFileConfigDO(FileConfigSaveReqVO reqVO) {
        FileStorageEnum storageEnum = FileStorageEnum.getByStorage(reqVO.getStorage());
        FileConfigDO config = BeanUtil.toBean(reqVO, FileConfigDO.class, new CopyOptions().setIgnoreProperties("config"));
        config.setConfig(BeanUtil.toBean(reqVO.getConfig(), storageEnum.getConfigClass()));
        return config;
    }


}
